import 'package:flutter/material.dart';
import '../../services/ScreenAdatper.dart';
import './CartNum.dart';
import '../../provider/Cart.dart';
import 'package:provider/provider.dart';

class CartItem extends StatefulWidget {
  Map itemData;
  CartItem(this.itemData, {Key key}) : super(key: key);

  _CartItemState createState() => _CartItemState();
}

class _CartItemState extends State<CartItem> {
  Map _itemData;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    this._itemData = widget.itemData;
  }

  @override
  Widget build(BuildContext context) {
    var cartProvider = Provider.of<Cart>(context);
    return Container(
      padding: EdgeInsets.all(5),
      height: ScreenAdatper.height(200),
      decoration: BoxDecoration(
          border: Border(bottom: BorderSide(width: 1, color: Colors.black12))),
      child: Row(
        children: <Widget>[
          Container(
            width: ScreenAdatper.width(60),
            child: Checkbox(
              value: _itemData['checked'],
              onChanged: (value) {
                setState(() {
                  _itemData['checked'] = value;
                  cartProvider.itemChage();
                });
              },
              activeColor: Colors.pink,
            ),
          ),
          Container(
            width: ScreenAdatper.width(160),
            child: Image.network(_itemData['pic'], fit: BoxFit.cover),
          ),
          Expanded(
            flex: 1,
            child: Container(
              padding: EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text("${_itemData['title']}",
                          style: TextStyle(fontSize: 16), maxLines: 2),
                      Text("规格：${_itemData['selectAttr']}"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        "￥ ${_itemData['price']}",
                        style: TextStyle(color: Colors.red),
                      ),
                      CartNum(this._itemData)
                    ],
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
